//
//  ReportCell.m
//  Azkar
//
//  Created by 王易 on 2018/8/28.
//  Copyright © 2018年 CPX. All rights reserved.
//

#import "ReportCell.h"

/**
 举报Cell
 */
@interface ReportCell()
@property (nonatomic,weak) UIImageView *selectedImage;

@property (nonatomic,weak) UILabel *title;
@end
@implementation ReportCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        MyRelativeLayout *rootLayout = [MyRelativeLayout new];
        rootLayout.backgroundColor = [UIColor whiteColor];
        rootLayout.wrapContentHeight = YES;
        rootLayout.cacheEstimatedRect = YES;
        rootLayout.myHorzMargin = 0;
        rootLayout.padding = UIEdgeInsetsMake(15, 12, 15, 12);
        self.rootLayout = rootLayout;
        [self.contentView addSubview:rootLayout];
        
        MyBorderline  *bld2 = [[MyBorderline alloc] initWithColor:Color(@"#EDEDED")];
        bld2.headIndent = bld2.tailIndent = 12;
        rootLayout.bottomBorderline = bld2;
        
        UIImageView *selectedImage = [UIImageView new];
        self.selectedImage = selectedImage;
        selectedImage.myVisibility = MyVisibility_Gone;
        selectedImage.image = Image(@"select_s");
        selectedImage.myWidth = 15;
        selectedImage.myHeight = 13;
        selectedImage.myTrailing = 3;
        selectedImage.myCenterY = 0;
        [rootLayout addSubview:selectedImage];
        
        UILabel *title = [UILabel new];
        self.title = title;
        title.textColor = Color(@"#525252");
        title.font = FontSize(16);
        title.myLeading = title.myTop = 0;
        title.trailingPos.equalTo(selectedImage.leadingPos).offset(5);
        title.wrapContentHeight = YES;
        [rootLayout addSubview:title];
        
        WeakSelf
        [rootLayout hyb_addTapGestureWithCallback:^(UITapGestureRecognizer *sender) {
           StrongSelf
            self.reportModel.isSelected = !self.reportModel.isSelected;
            self.reportModel = self.reportModel;
        }];
    }
    return self;
}
- (void)setReportModel:(ReportListModel *)reportModel
{
    _reportModel = reportModel;
    
    self.title.text = reportModel.report_type;
    [self.title sizeToFit];
    self.title.textColor = reportModel.isSelected ? Color(@"#00732F") : Color(@"#525252");
    self.selectedImage.myVisibility = reportModel.isSelected ? MyVisibility_Visible : MyVisibility_Gone;
     self.title.textAlignment = [MyBaseLayout isRTL] ? NSTextAlignmentRight : NSTextAlignmentLeft;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
